package crp.services.api.graphql.models;

import com.fasterxml.jackson.annotation.JsonIgnore;
import crp.core.workflow.domain.models.WorkflowDefinition;
import crp.core.workflow.domain.models.WorkflowModelEntity;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import org.eclipse.microprofile.graphql.Id;
import org.eclipse.microprofile.graphql.Type;

import javax.validation.constraints.NotNull;

@Type("WorkflowModel")
@Builder
@Getter
@AllArgsConstructor
public class WorkflowModelPayload {
    @Id
    @NotNull
    private final String id;
    @NotNull
    private final String name;
    @NotNull
    private final String topic;
    @JsonIgnore
    private final WorkflowDefinition definition;
    @JsonIgnore
    private final String instanceId;

    public static WorkflowModelPayload of(WorkflowModelEntity entity, String instanceId) {
        return WorkflowModelPayload.builder()
                .id(entity.getId())
                .name(entity.getName())
                .topic(entity.getTopic())
                .definition(entity.getDefinition())
                .instanceId(instanceId)
                .build();
    }
}
